import { FormSchema } from '/@/components/Table';

const isSQL = (type) => type === 'SQL';
const isTEXT= (type) => type === 'TEXT';
export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'enable',
    label: 'enable',
    component: 'Input',
    show: false,
    defaultValue: false,
  },
  {
    field: 'subType',
    label: '类型',
    component: 'Input',
    show: false,
  },
  {
    field: 'driverClassName',
    label: 'JDBC驱动类名',
    component: 'Select',
    componentProps: {
      options: [
        { label: 'com.mysql.cj.jdbc.Driver', value: 'com.mysql.cj.jdbc.Driver' },
        { label: 'oracle.jdbc.OracleDriver', value: 'oracle.jdbc.OracleDriver' },
        { label: 'org.postgresql.Driver', value: 'org.postgresql.Driver' },
        { label: 'com.microsoft.sqlserver.jdbc.SQLServerDriver', value: 'com.microsoft.sqlserver.jdbc.SQLServerDriver' },
      ],
    },
    required: true,
    ifShow: ({ values }) => isSQL(values.subType),
  },
  {
    field: 'jdbcUrl',
    label: 'JDBC连接地址',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.subType),
  },
  {
    field: 'username',
    label: '数据库用户名',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.subType),
  },
  {
    field: 'password',
    label: '数据库密码',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isSQL(values.subType),
  },
  {
    field: 'proxySql',
    label: '代理SQL',
    component: 'Input',
    defaultValue: "select qos,topic from ProxySubscribe where clientId = '${clientId}'",
    required: true,
    ifShow: ({ values }) => isSQL(values.subType),
  },
  {
    field: 'subInfos',
    label: '订阅列表',
    component: 'Input',
    slot: 'fixedAuth',
    ifShow: ({ values }) => isTEXT(values.subType),
  },
  {
    field: 'filter',
    label: '匹配规则',
    component: 'Input',
    componentProps: {
      placeholder: 'fluxmql{clientId}',
    },
  },
];

export interface ActionBtn {
  img?: string;
  click?: object;
  isshow?: boolean;
  name?: string;
  params?: string;
}

export const actionBtns: ActionBtn[] = [
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleRun',
    },
  },
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleEdit',
    },
  },
  {
    img: '',
    click: {
      isshow: true,
      name: 'handleRun',
    },
  },
  {
    img: '',
    click: {
      defaultshow: true,
      name: 'handleDetail',
    },
  },
  {
    img: '',
    click: {
      isshow: false,
      name: 'handleDelete',
    },
  },
];
export interface AuthType {
  img?: string;
  name?: string;
  type?: string;
  desc?: string;
}
export const authType: AuthType[] = [
  {
    img: '',
    name: '数据库代理主题',
    type: 'SQL',
    desc: '动态读取数据库，完成设备的主题订阅',
  },
  {
    img: '',
    name: '固定代理主题',
    type: 'TEXT',
    desc: '读取固定主题信息，完成设备的主题订阅',
  },
];
